/**
 * 
 */
package top.ljjapp.security.core.authentication;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import top.ljjapp.security.core.properties.SecurityConstants;


/**
 * 配置登录拦截配置
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	protected AuthenticationSuccessHandler myAuthenticationSuccessHandler;
	
	@Autowired
	protected AuthenticationFailureHandler myAuthenticationFailureHandler;
	
	protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
		http.formLogin() //表单登录
			.loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL) //自定义页面，需要配置授权
																       //可跳转到controller中
			.loginProcessingUrl(SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM) //security默认表单验证是UsernamePasswordAuthenticationFilter做的，
																					 // 请求url是login,请求方式是POST.
																				     // 这里定义自定义的请求路径，请求内容就会到
			.successHandler(myAuthenticationSuccessHandler) //成功登录后的处理
			.failureHandler(myAuthenticationFailureHandler) //失败后的处理
		;
	}
	
}
